package com.xj0927.cloud.controller;

import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.xj0927.cloud.service.OrderHystrixService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: xj0927
 * @Description:
 * @Date Created in 2020-10-30 9:46
 * @Modified By:
 */
@RestController
@Slf4j
@DefaultProperties(defaultFallback = "payment_Global_FallbackMethod")//定义全局fallback
public class OrderHystrixController {
    @Autowired
    private OrderHystrixService service;

    @GetMapping("/consumer/payment/hystrix/ok/{id}")
    public String payment_ok(@PathVariable Integer id){
        return service.payment_ok(id);
    }

    @GetMapping("/consumer/payment/hystrix/outTime/{id}")
//    @HystrixCommand(fallbackMethod = "paymentInfo_TimeOutHandler",commandProperties = {
//            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "1500")
//    })
    @HystrixCommand  //不指定具体的哪一个处理方法
    public String payment_outTime(@PathVariable Integer id){
        int time = 10/0;//模拟异常情况
        return service.payment_outTime(id);
    }
    //对应处理措施
    public String paymentInfo_TimeOutHandler(Integer id){
        return "我是消费方80，出现超时等待或异常了";
    }

    //下面是全局fallback
    public String payment_Global_FallbackMethod(){
        return "Global异常处理信息，请稍后再试~~";
    }
}
